package com.jadcon.harveycedars.model.dormitory;

import java.util.*;

import org.springframework.stereotype.Component;

@Component("PersonRepository")
public class PersonRepositoryInMemoryImpl implements PersonRepository {
	private List<Person> personList = new ArrayList<Person>();

	public PersonRepositoryInMemoryImpl () {
		
		// hard coded data
		Person bob = new Person("Bob Stevens", Gender.MALE, "New Hanover", 14);
		Person mary = new Person("Mary Johnson", Gender.FEMALE, "New Hanover", 16);
		Person larry = new Person("Larry Jones", Gender.MALE, "New Life", 13);
		Person steve = new Person("Stevie Wonder", Gender.MALE, "New life", 18);
		Person luke = new Person("Luke Skywalker", Gender.MALE, "Hope", 17);
		Person darth = new Person("Darth Vadar", Gender.MALE, "Hope", 12);
		Person Jessie = new Person("Jessie Hartman", Gender.MALE, "Danville", 15);
	
		personList.add(bob);
		personList.add(mary);
		personList.add(larry);
		personList.add(steve);
		personList.add(luke);
		personList.add(darth);
		personList.add(Jessie);
		
	}

	public void save(Person person) {
		personList.add(person);
	}
	
	public List<Person> getPersonList() {
		return personList;
	}

	public void setPersonList(List<Person> personList) {
		this.personList = personList;
	}
	
	public Person findPersonByFullName(String fullname) {
		for (Person person : personList) {
			System.out.println("String one " + fullname.hashCode() + "=" + fullname.toString() + " String two " + person.getFullname().hashCode() + "=" + person.getFullname().toString());
			if (person.getFullname().equalsIgnoreCase(fullname)) {
				return person;
			}
		}
		
		// two test whether two strings have the same value, use the ".equals()" NOT "=="
		// .equals() tests the value of the strings
		// "==" operator sees if it is the same instance\object (two leashes to same object)

		return null;
	}




	
}

	
	



